/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.PassengerServiceInfo;
import com.sasis.model.VipServiceSheet;
import com.sasis.dao.VipServiceSheetDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class VipServiceSheetDaoiBatis extends BaseDaoiBATIS implements VipServiceSheetDao {

    /**
     * @see com.sasis.dao.VipServiceSheetDao#getVipServiceSheets(com.sasis.model.VipServiceSheet)
     */
    public List getVipServiceSheets(final VipServiceSheet vipServiceSheet) {
    	  	return getSqlMapClientTemplate().queryForList("getVipServiceSheets", vipServiceSheet);
    }
    
    
    public List getPassengerServiceInfos(final PassengerServiceInfo passengerServiceInfo){
    	
    	return getSqlMapClientTemplate().queryForList("getPassengerServiceInfos", passengerServiceInfo);
    }

    /**
     * @see com.sasis.dao.VipServiceSheetDao#getVipServiceSheet(Integer id)
     */
    public VipServiceSheet getVipServiceSheet(Integer id) {
        VipServiceSheet vipServiceSheet = (VipServiceSheet) getSqlMapClientTemplate().queryForObject("getVipServiceSheet", id);

        if (vipServiceSheet == null) {
            throw new ObjectRetrievalFailureException(VipServiceSheet.class, id);
        }

        return vipServiceSheet;
    }

    /**
     * @see com.sasis.dao.VipServiceSheetDao#saveVipServiceSheet(VipServiceSheet vipServiceSheet)
     */    
    public void saveVipServiceSheet(final VipServiceSheet vipServiceSheet) {
        Integer id = vipServiceSheet.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addVipServiceSheet", vipServiceSheet);
        } else {
            getSqlMapClientTemplate().update("updateVipServiceSheet", vipServiceSheet);
        }
//        if( id == null ) {
//            throw new ObjectRetrievalFailureException(VipServiceSheet.class, id);
//        }
    }
    
    public void updateVipServiceSheetApproved(final VipServiceSheet vipServiceSheet) {
        Integer id = vipServiceSheet.getId();
        // check for new record
        if (id != null) {
            getSqlMapClientTemplate().update("updateVipServiceSheetApproved", vipServiceSheet);
        }else{
        	throw new ObjectRetrievalFailureException(VipServiceSheet.class, id);
        }
    }

    /**
     * @see com.sasis.dao.VipServiceSheetDao#removeVipServiceSheet(Integer id)
     */
    public void removeVipServiceSheet(VipServiceSheet vipServiceSheet) {
        getSqlMapClientTemplate().update("deleteVipServiceSheet",  vipServiceSheet);
    }
}
